package utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import rsa.RSAKey;

public class LoginData implements Serializable{

	private static final long serialVersionUID = 1L;
	private String username=null;
	private String password=null;
	private RSAKey clientPublicKey=null;
	
	public LoginData(String usern, String passwd, RSAKey clientPublicKey) {
		setUsername(usern);
		setPassword(passwd);
		setClientPublicKey(clientPublicKey);
	}
	
	public LoginData() {
		
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public byte[] toByteArray(){
		
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutput out = null;
		byte[] loginInBytes=null;
		try {
		  try {
			out = new ObjectOutputStream(bos);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
		  try {
			out.writeObject(this);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  loginInBytes = bos.toByteArray();
		} 
		finally {
			  try {
			    if (out != null) {
			      out.close();
			    }
			  } catch (IOException ex) {
			    // ignore close exception
			  }
			  try {
			    bos.close();
			  } catch (IOException ex) {
			    // ignore close exception
			  }
			}
		return loginInBytes;
		
	}
	public RSAKey getClientPublicKey() {
		return clientPublicKey;
	}
	public void setClientPublicKey(RSAKey clientPublicKey) {
		this.clientPublicKey = clientPublicKey;
	}

	
	
	
}
